//
//  ZLoginHandle.m
//  WeClubs
//
//  Created by KevinWang on 17/3/27.
//  Copyright © 2017年 Zed. All rights reserved.
//

#import "ZLoginHandle.h"
#import <RongIMLib/RongIMLib.h>
#import "JPUSHService.h"
#import "ThirdPartKeyDefine.h"
#import "ZUserInfo.h"
@implementation ZLoginHandle

static ZLoginHandle * instance = nil;

+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc]init];
    });
    
    return instance;
}

- (BOOL)isLoginStatus
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:isLogin];
}

- (void)setIsLoginStatus:(BOOL)isLoginStatus
{
    NSUserDefaults * userdefault = [NSUserDefaults standardUserDefaults];
    
    [userdefault setBool:isLoginStatus forKey:isLogin];
    [userdefault synchronize];
}

- (void)RongCloudConfig{
    //init
    [[RCIMClient sharedRCIMClient] initWithAppKey:TestRongCloudAppKey];
    
    [HTTPRequest POST:kIm_get_token parameter:nil success:^(id resposeObject) {
        NSString *im_token = resposeObject[@"data"][@"im_token"];
        [[RCIMClient sharedRCIMClient] connectWithToken:im_token success:^(NSString *userId) {
            ZLog(@"登陆成功。当前登录的用户ID：%@", userId);
        } error:^(RCConnectErrorCode status) {
            ZLog(@"登陆的错误码为:%ld", (long)status);
        } tokenIncorrect:^{
            ZLog(@"token错误");
        }];
    } failure:^(NSError *error) {
        ZLog(@"%@",error);
    }];
    
}

- (void)JPushConfig{
    //JPush设置别名
    [JPUSHService setAlias:[NSString stringWithFormat:@"user_%ld",[ZUserInfo sharedInstance].userId] callbackSelector:nil object:nil];
}

@end
